package com.ty.web;

import com.ty.bean.Grade;
import com.ty.bean.Student;
import com.ty.service.GradeService;
import com.ty.service.StudentService;
import com.ty.service.impl.GradeServiceImpl;
import com.ty.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 田野
 */
@WebServlet(urlPatterns = "/Educational/student/findById")
public class FindByIdServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1、接收参数
        String sid = req.getParameter("sid");
        // 测试一把，控制台输出
        System.out.println("主键查询的sid" + sid);
        // 2、调用service层
        StudentService service = new StudentServiceImpl();
        if (sid != null){
            Student student= service.findById(Integer.parseInt(sid));
            req.setAttribute("stu", student);

            // 查询年级列表
            GradeService gradeService = new GradeServiceImpl();
            List<Grade> list = gradeService.getList();
            req.setAttribute("list", list);
            // 3、跳转页面
            req.getRequestDispatcher("edit.jsp").forward(req, resp);

        }

    }
}
